package com.sms.web.system.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.sms.common.BaseEntity;


/**
 * @desc 菜单实体类
 * @author WuJiangWu
 * @date 2018年7月23日下午11:46:16
 */
@Entity
@Table(name = "sys_menu")
public class SysMenu extends BaseEntity {

	private static final long serialVersionUID = 1L;

	@Id
    @GeneratedValue(generator = "UIDGenerator")
    @GenericGenerator(name = "UIDGenerator", strategy = "com.sms.common.persistence.UIDGenerator")
    @Column(length = 40)
	private String id;
	
	/** 菜单名称 */
	@Column(length = 50)
	private String menuName;
	/** 菜单路径 */
	@Column(length = 200)
	private String menuUrl;
	/** 菜单图标 */
	@Column(length = 50)
	private String menuIcon;
	
	/** 父级菜单 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @JoinColumn(name = "parent_id")
    private SysMenu parent;
    
	/** 排序 */
	@Column(length = 10)
	private Integer sort;
	
	
	public SysMenu() {
		super();
	}
	
	public SysMenu(String id) {
		this.id = id;
	}
	
	/** 子菜单集合 */
	@JsonIgnore
	@OrderBy("sort asc")
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parent")
	private List<SysMenu> childList = new ArrayList<SysMenu>();
	
	public String getMenuName() {
		return menuName;
	}
	public void setMenuName(String menuName) {
		this.menuName = menuName;
	}
	public String getMenuUrl() {
		return menuUrl;
	}
	public void setMenuUrl(String menuUrl) {
		this.menuUrl = menuUrl;
	}
	public String getMenuIcon() {
		return menuIcon;
	}
	public void setMenuIcon(String menuIcon) {
		this.menuIcon = menuIcon;
	}
	public Integer getSort() {
		return sort;
	}
	public void setSort(Integer sort) {
		this.sort = sort;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public SysMenu getParent() {
		return parent;
	}
	public void setParent(SysMenu parent) {
		this.parent = parent;
	}
	public List<SysMenu> getChildList() {
		return childList;
	}
	public void setChildList(List<SysMenu> childList) {
		this.childList = childList;
	}
	
}
